package com.hohai.river.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hohai.river.entity.Yuleiindex;
import com.hohai.river.service.YuleiindexService;
import com.hohai.river.service.impl.IndexService;
import com.pig4cloud.pig.common.core.util.R;
import com.pig4cloud.pig.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 鱼类保有指数表
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/yuleiindex")
@Tag(name = "鱼类保有指数表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class YuleiindexController {

	private final YuleiindexService yuleiindexService;

	@Autowired
	private IndexService indexService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param yuleiindex 鱼类保有指数表
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('river_index_get')")
	public R getYuleiindexPage(Page page, Yuleiindex yuleiindex) {
		return R.ok(yuleiindexService.page(page, Wrappers.query(yuleiindex)));
	}

	/**
	 * 通过id查询鱼类保有指数表
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('river_index_get')")
	public R getById(@PathVariable("id") Long id) {
		return R.ok(yuleiindexService.getById(id));
	}

	/**
	 * 新增鱼类保有指数表
	 * @param yuleiindex 鱼类保有指数表
	 * @return R
	 */
	@Operation(summary = "新增鱼类保有指数表", description = "新增鱼类保有指数表")
	@SysLog("新增鱼类保有指数表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('river_index_add')")
	public R save(@RequestBody Yuleiindex yuleiindex, @RequestParam("indexId") Long indexId) {
		return R.ok(indexService.addIndex(yuleiindex, indexId, yuleiindexService));
	}

	/**
	 * 修改鱼类保有指数表
	 * @param yuleiindex 鱼类保有指数表
	 * @return R
	 */
	@Operation(summary = "修改鱼类保有指数表", description = "修改鱼类保有指数表")
	@SysLog("修改鱼类保有指数表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('river_index_edit')")
	public R updateById(@RequestBody Yuleiindex yuleiindex, @RequestParam("indexId") Long indexId) {
		return R.ok(indexService.updateIndex(yuleiindex, indexId, yuleiindexService));
	}

	/**
	 * 通过id删除鱼类保有指数表
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "通过id删除鱼类保有指数表", description = "通过id删除鱼类保有指数表")
	@SysLog("通过id删除鱼类保有指数表")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('river_index_del')")
	public R removeById(@PathVariable Long id) {
		return R.ok(yuleiindexService.removeById(id));
	}

	/**
	 * 条件查询
	 */
	@Operation(summary = "条件查询", description = "条件查询")
	@GetMapping
	@PreAuthorize("@pms.hasPermission('river_index_get')")
	public R conditionQuery(@RequestParam("riverId") Long riverId, @RequestParam("fillType") Integer fillType) {
		return R.ok(indexService.conditionQuery(riverId, fillType, yuleiindexService));
	}

	/**
	 * 查询专家填写列表
	 */
	@Operation(summary = "查询专家填写列表", description = "查询专家填写列表")
	@GetMapping("/expert/list")
	@PreAuthorize("@pms.hasPermission('river_report_audit')")
	public R getExpertFillList(@RequestParam("riverId") Long riverId) {
		return R.ok(yuleiindexService.getExpertFillList(riverId));
	}

	/**
	 * 删除支撑材料
	 * @param id id
	 * @return R
	 */
	@Operation(summary = "删除支撑材料", description = "删除支撑材料")
	@SysLog("删除支撑材料")
	@PutMapping("/delfile/{id}")
	@PreAuthorize("@pms.hasPermission('river_index_edit')")
	public R delFile(@PathVariable Long id, @RequestParam("fileName") String fileName) {
		return R.ok(indexService.delFile(id, fileName, yuleiindexService));
	}

}
